package exam.xiaohongshu.S3;

import java.util.*;

public class Main {
    public static int n;
    public static Set<Integer>[] friends;
    public static int maxPair = 0;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        friends = new Set[n];
        for (int i=0; i<n; ++i)
            friends[i] = new HashSet<>();
        for (int i=0; i<n-1; ++i) {
            int v = sc.nextInt();
            friends[i+1].add(v-1);
            friends[v-1].add(i+1);
        }
        solution();
        System.out.println(maxPair);
    }

    private static void solution() {
        if (n > 100)
            return;
        Set<Integer> used = new HashSet<>();
        dfs(used, 0);
    }

    private static void dfs(Set<Integer> used, int pair) {
        if (pair > maxPair)
            maxPair = pair;
        for (int i=0; i<n; ++i) {
            if (used.contains(i))
                continue;
            int u = i;
            // 要u
            for (int v : friends[u]) {
                if (used.contains(v))
                    continue;
                used.add(u);
                used.add(v);
                dfs(used, pair+1);
                used.remove(u);
                used.remove(v);
            }
            // 不要u

        }
    }
}